package com.tgh.au.c5;

import java.util.concurrent.TimeUnit;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

public class GameView5 extends View implements Runnable {
	private Paint paint;
	private int count=0;
	
	private TextUtil textUtil;
	
	public GameView5(Context context) {
		super(context);
		setFocusable(true);
		requestFocus();
		paint=new Paint();
		String text="测试自动换行\n\n设置文字自动换行abcdefgh\niklmnopqrst换行123347465\n43756245Android\n设置文字自动换行abcdefgh\niklmnopqrst换行123347465\n43756245Android";
		textUtil=new TextUtil();
		textUtil.initText(text,5,50,300,80,0x0,0xffffff,255,16);
		new Thread(this).start();
	}

	public void run() {
		while (!Thread.currentThread().isInterrupted()) {
			try {
				TimeUnit.MILLISECONDS.sleep(100);
			} catch (Exception e) {
				Thread.currentThread().interrupt();
			}
			postInvalidate();
		}
	}
	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawColor(Color.BLACK);
		paint.setAntiAlias(true);
		if (count<100) {
			count++;
		}
		paint.setColor(Color.RED);
		canvas.drawText("装载进度："+count+"%......", 10, 20, paint);
		textUtil.drawText(canvas);
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return textUtil.keyDown(keyCode, event);
	}
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		return false;
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return true;
	}
	@Override
	public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
		return true;
	}
}
